home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / slapfght.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  3KB  |  171 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12.  
  13. unsigned char *slapfight_dpram;
  14. size_t slapfight_dpram_size;
  15.  
  16. int slapfight_status;
  17. int getstar_sequence_index;
  18. int getstar_sh_intenabled;
  19.  
  20. static int slapfight_status_state;
  21. extern unsigned char *getstar_e803;
  22.  
  23. /* Perform basic machine initialisation */
  24.  
  25. void slapfight_init_machine(void)
  26. {
  27.     /* MAIN CPU */
  28.  
  29.     slapfight_status_state=0;
  30.     slapfight_status = 0xc7;
  31.  
  32.     getstar_sequence_index = 0;
  33.     getstar_sh_intenabled = 0;    /* disable sound cpu interrupts */
  34.  
  35.     /* SOUND CPU */
  36.     cpu_set_reset_line(1,ASSERT_LINE);
  37. }
  38.  
  39. /* Interrupt handlers cpu & sound */
  40.  
  41. WRITE_HANDLER( slapfight_dpram_w )
  42. {
  43.     slapfight_dpram[offset]=data;
  44.  
  45. //    logerror("SLAPFIGHT MAIN  CPU : Write to   $c8%02x = %02x\n",offset,slapfight_dpram[offset]);
  46.  
  47.  
  48. /*
  49.  
  50.     // Synchronise CPUs
  51.     timer_set(TIME_NOW,0,0);       P'tit Seb 980926 Commented out because it doesn't seem to be necessary
  52.  
  53.     // Now cause the interrupt
  54.     cpu_cause_interrupt (1, Z80_NMI_INT);
  55.  
  56. */
  57.  
  58.  
  59.     return;
  60. }
  61.  
  62. READ_HANDLER( slapfight_dpram_r )
  63. {
  64.     return slapfight_dpram[offset];
  65. }
  66.  
  67.  
  68.  
  69. /* Slapfight CPU input/output ports
  70.  
  71.   These ports seem to control memory access
  72.  
  73. */
  74.  
  75. /* Reset and hold sound CPU */
  76. WRITE_HANDLER( slapfight_port_00_w )
  77. {
  78.     cpu_set_reset_line(1,ASSERT_LINE);
  79.     getstar_sh_intenabled = 0;
  80. }
  81.  
  82. /* Release reset on sound CPU */
  83. WRITE_HANDLER( slapfight_port_01_w )
  84. {
  85.     cpu_set_reset_line(1,CLEAR_LINE);
  86. }
  87.  
  88. /* Disable and clear hardware interrupt */
  89. WRITE_HANDLER( slapfight_port_06_w )
  90. {
  91.     interrupt_enable_w(0,0);
  92. }
  93.  
  94. /* Enable hardware interrupt */
  95. WRITE_HANDLER( slapfight_port_07_w )
  96. {
  97.     interrupt_enable_w(0,1);
  98. }
  99.  
  100. WRITE_HANDLER( slapfight_port_08_w )
  101. {
  102.     unsigned char *RAM = memory_region(REGION_CPU1);
  103.  
  104.     cpu_setbank(1,&RAM[0x10000]);
  105. }
  106.  
  107. WRITE_HANDLER( slapfight_port_09_w )
  108. {
  109.     unsigned char *RAM = memory_region(REGION_CPU1);
  110.  
  111.     cpu_setbank(1,&RAM[0x14000]);
  112. }
  113.  
  114.  
  115. /* Status register */
  116.  
  117. READ_HANDLER( slapfight_port_00_r )
  118. {
  119.     int states[3]={ 0xc7, 0x55, 0x00 };
  120.  
  121.     slapfight_status = states[slapfight_status_state];
  122.  
  123.     slapfight_status_state++;
  124.     if (slapfight_status_state > 2) slapfight_status_state = 0;
  125.  
  126.     return slapfight_status;
  127. }
  128.  
  129.  
  130.  
  131. /*
  132.  Reads at e803 expect a sequence of values such that:
  133.  - first value is different from successive
  134.  - third value is (first+5)^0x56
  135.  I don't know what writes to this address do (connected to port 0 reads?).
  136. */
  137. READ_HANDLER( getstar_e803_r )
  138. {
  139. unsigned char seq[] = { 0, 1, (0+5)^0x56 };
  140. unsigned char val;
  141.  
  142.     val = seq[getstar_sequence_index];
  143.     getstar_sequence_index = (getstar_sequence_index+1)%3;
  144.     return val;
  145. }
  146.  
  147.  
  148.  
  149. /* Enable hardware interrupt of sound cpu */
  150. WRITE_HANDLER( getstar_sh_intenable_w )
  151. {
  152.     getstar_sh_intenabled = 1;
  153.     logerror("cpu #1 PC=%d: %d written to a0e0\n",cpu_get_pc(),data);
  154. }
  155.  
  156.  
  157.  
  158. /* Generate interrups only if they have been enabled */
  159. int getstar_interrupt(void)
  160. {
  161.     if (getstar_sh_intenabled)
  162.         return nmi_interrupt();
  163.     else
  164.         return ignore_interrupt();
  165. }
  166.  
  167. WRITE_HANDLER( getstar_port_04_w )
  168. {
  169. //    cpu_halt(0,0);
  170. }
  171.